import { builtinModules } from 'module'

import typescript from '@rollup/plugin-typescript'
import nodeResolve from '@rollup/plugin-node-resolve'

export function createConfig({ input = 'index.ts', pkg = {}, external = [] }) {
    return [
        {
            input: input,
            external: Object.keys(pkg.dependencies || {})
                .concat(Object.keys(pkg.peerDependencies || {}))
                .concat(builtinModules)
                .concat(external),
            strictDeprecations: true,
            output: {
                file: pkg.module,
                format: 'es',
                sourcemap: true
            },
            plugins: [typescript({ sourceMap: true })]
        },
        {
            input: input,
            strictDeprecations: true,
            output: {
                file: pkg.browser,
                format: 'es',
                sourcemap: true,
                entryFileNames: '[name].min.js'
            },
            plugins: [
                nodeResolve(),
                typescript({ sourceMap: true })
            ]
        }
    ]
}
